Skip to content

PERF: maintain root when signing ItemCollections - #30

Merged
Tom Augspurger (TomAugspurger) merged 1 commit into
microsoft:mainfrom
gjoseph92:maintain-root-while-signing
Oct 29, 2021
Merged

Tom Augspurger (TomAugspurger) merged 1 commit into
microsoft:mainfrom
gjoseph92:maintain-root-while-signing

Conversation

@gjoseph92

Copy link
Copy Markdown
Contributor

Losing the root collection was causing to_dict() on signed ItemCollections to be extremely slow, like stac-utils/pystac#546. By preserving the root catalog stac-utils/pystac-client#72, it's much faster.

Before this PR:

catalog = pystac_client.Client.open('https://planetarycomputer.microsoft.com/api/stac/v1')
search = catalog.search(
    collections=['landsat-8-c2-l2'],
    bbox=bbox,
    limit=10_000,
)
items = search.get_all_items()

%time _ = items.to_dict()
# Wall time: 65.8 ms

%time signed = pc.sign(items)
# Wall time: 628 ms

%time _ = signed.to_dict()
# Wall time: 1min 52s

Losing the root collection was causing `to_dict()` on signed `ItemCollections` to be extremely slow, like stac-utils/pystac#546. By preserving the root catalog stac-utils/pystac-client#72, it's much faster.
@ghost

Deleted user (ghost) commented Oct 29, 2021 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@TomAugspurger

Copy link
Copy Markdown

Thanks. Agreed that signing the ItemCollection should keep the root link.

Just to confirm the changes to the test files: the need to call resolve at https://github.com/microsoft/planetary-computer-sdk-for-python/pull/30/files#diff-486d907e95067ba6beb5f4579e73e64be6c4ddb448e4cba7c19bbfa26bc3a595R36-R38 is to ensure that we're not dropping links accidentally? It doesn't mean that there's a behavior change here (e.g. we could previously sign unresolved item collections, but now we can't?)

@gjoseph92

Copy link
Copy Markdown
Contributor Author

Yeah, I should document that. It's just to simulate the result of a search, basically, and make it so the input already has a resolved root link (otherwise there's nothing to test). If you want we could parametrize on resolved/not resolved. Or just remove the link from one of the JSON files.

@TomAugspurger

Copy link
Copy Markdown

I think we're good with the tests as is. Thanks!

I'll make a release with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants